//
//  BKHomeCycleModel.m
//  FastBee
//
//  Created by mac on 16/9/9.
//  Copyright © 2016年 xbk. All rights reserved.
//

#import "BKHomeCycleModel.h"
#import "BKNetWorkTools.h"
#import <AFNetworking.h>

@implementation BKHomeCycleModel

+ (instancetype)cycleModelWithDic:(NSDictionary*)dic{

    BKHomeCycleModel *model = [[BKHomeCycleModel alloc]init];
    [model setValuesForKeysWithDictionary:dic];
    return model;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{

}


+ (void)downloadDataWithUrl:(NSString *)url successBlock:(void (^)(NSArray *))successBlock failBlock:(void (^)(NSError *))failBlock{

    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:@"1" forKey:@"call"];
    [[BKNetWorkTools shareNetWorkTools]POST:url parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
        
        //NSLog(@"%@",responseObject);
        NSDictionary *dic = [responseObject objectForKey:@"data"];
        NSArray *arr = dic[@"focus"];
        NSMutableArray *arrM = [NSMutableArray array];
        
        for (NSDictionary *dic in arr) {
            
            BKHomeCycleModel *model = [BKHomeCycleModel cycleModelWithDic:dic];
            [arrM addObject:model];
        }
        
        if (successBlock) {
            
            successBlock(arrM.copy);
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        if (failBlock) {
            
            failBlock(error);
        }
        
    }];
}

@end
